package com.example.keli.ui.list;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.keli.R;
import com.example.keli.base.utils.GlideUtil;
import com.example.keli.ui.home.activity.ObjectDetailActivity;

import java.util.List;

/**
 * description:助力榜单适配器
 * author: Allen
 * date: 2019/3/19 11:51
 */
public class TicketAdapter extends BaseQuickAdapter<TicketData.DataBean, BaseViewHolder> {
    int flag = 0;
    public TicketAdapter(List<TicketData.DataBean> mData,int flag) {
        super(R.layout.item_user_list, mData);
        this.flag = flag;
    }

    @Override
    protected void convert(BaseViewHolder helper, final TicketData.DataBean mListBean) {
        helper.setText(R.id.nick_name, mListBean.getNickname());
        if(flag==0){
            //助力榜
            helper.setText(R.id.num, mListBean.getTicket_num() + "次");
        }else{
            //粉丝榜
            helper.setText(R.id.num, mListBean.getGift_num() + "份");
        }
        ImageView avatar = helper.getView(R.id.avatar);
        ImageView icon = helper.getView(R.id.icon);
        CardView layout = helper.getView(R.id.layout);
        TextView tv_rank = helper.getView(R.id.tv_rank);
        GlideUtil.displayCircle(avatar.getContext(), avatar, mListBean.getAvatar());
        int position = helper.getLayoutPosition();
        icon.setVisibility(View.VISIBLE);
        tv_rank.setText("");
        if (position == 0) {
            layout.setCardBackgroundColor(ContextCompat.getColor(layout.getContext(), R.color.one_bg));
            icon.setImageResource(R.mipmap.one_icon);
        } else if (position == 1) {
            layout.setCardBackgroundColor(ContextCompat.getColor(layout.getContext(), R.color.two_bg));
            icon.setImageResource(R.mipmap.two_icon);
        } else if (position == 2) {
            layout.setCardBackgroundColor(ContextCompat.getColor(layout.getContext(), R.color.three_bg));
            icon.setImageResource(R.mipmap.three_icon);
        } else {
            layout.setCardBackgroundColor(ContextCompat.getColor(layout.getContext(), R.color.white));
            icon.setVisibility(View.GONE);
            tv_rank.setText("NO." + (position + 1));
        }
        avatar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectDetailActivity.start(mContext,String.valueOf(mListBean.getUid()),String.valueOf(mListBean.getAaid()));
            }
        });
    }

}
